<?php
function db_connect(){
 $conn_result= new mysqli('localhost','root','1234','bookmarks');
 if ($conn_result) {
 	return $conn_result;
 } else {
 	throw new Exception("数据库连接失败", 1);
 	return false;
 	}
 }
function check_password($password){
	if ($password!=""&&strlen($password)>6&&strlen($password)<12) {
		return true;
	} else {
		throw new Exception("输入密码有误", 3);
		return false;
	}	
}
function check_email($email){
	if ($email!=""&&ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $email)) {
		return true;
	} else {
		throw new Exception("邮箱格式有误", 4);
		return false;
	}
}
function check_username($username){
	if ($username!=""&&strlen($username)>6&&strlen($username)<25) {
		return true;
	} else {
		throw new Exception("输入用户名有误", 3);
		return false;
	}	
}
function check_url($url){
	if ($url!=""&&@ereg('^(https?://)?([\da-z\.-]+)\.([a-z\.]{2,6})([/\w \.-]*)*/?$', $url)) {
		return true;
	} else {
		throw new Exception("url格式有误", 4);
		return false;
	}
}
function log_out(){
	if (isset($_SESSION['valid_user'])) {
		unset($_SESSION['valid_user']);
		session_destroy();
	}
}
?>